﻿using aier.dataaccess.model;
using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aier.dataaccess.dapper
{
    public class ContentDal
    {
        public DapperHelper dapperHelper { get; set; }
        /// <summary>
        /// 获取所有筛查内容
        /// 原程序 ScContentServiceImpl/getAll
        /// </summary>
        /// <returns></returns>
        public List<ContentView> GetAllContentInfo()
        {

            List<ContentView> contentViews = null;
            SqlBuilder sqlBuilder = new SqlBuilder();
            DynamicParameters sqlParams = new DynamicParameters();

            dapperHelper.ExecueWithoutTransaction(a =>
            {
                string sql = @"select * from AIER_T_SC_CONTENT";
                var sqlTemplate = sqlBuilder.AddTemplate(sql);

                contentViews = a.Query<ContentView>(sqlTemplate.RawSql, sqlParams).ToList();
            });

            return contentViews;

        }
        /// <summary>
        /// 根据筛查内容ID获取筛查内容
        /// 查询条件：筛查内容ID
        /// 原程序 ScContentServiceImpl/getById
        /// </summary>
        /// <returns></returns>
        public ContentView GetContentInfoById(string ContentId)
        {

            ContentView contentView = null;
            SqlBuilder sqlBuilder = new SqlBuilder();
            DynamicParameters sqlParams = new DynamicParameters();

            dapperHelper.ExecueWithoutTransaction(a =>
            {
                string sql = @"select * from AIER_T_SC_CONTENT  /**where**/";
                var sqlTemplate = sqlBuilder.AddTemplate(sql);
                if (!string.IsNullOrWhiteSpace(ContentId))
                {
                    sqlBuilder.Where("new_contentid=@new_contentid");
                    sqlParams.Add("@new_contentid", ContentId);
                }
                contentView = a.QueryFirstOrDefault<ContentView>(sqlTemplate.RawSql, sqlParams);
            });

            return contentView;

        }
    }
}
